package com.bb.blog.security.service;

import com.bb.blog.security.dao.UserMapper;
import com.bb.blog.security.model.BbUserDetail;
import com.bb.blog.security.model.User;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@RequiredArgsConstructor
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    private  final UserMapper userMapper;

    private final ResourcesService resourcesService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.selectByUsername(username);
        return new BbUserDetail(user, resourcesService.loadResourcesByUserId(user.getId()));
    }
}
